﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Linyb.Linq.QueryExtension
{
    public interface IComparePredicate : IBasePredicate
    {
        Operator Operator { get; set; }
        bool Not { get; set; }
    }

    public abstract class ComparePredicate : BasePredicate
    {
        public Operator Operator { get; set; }
        public bool Not { get; set; }

        public virtual string GetConditionString(string columnName, string parameterName)
        {
            if (Operator == Operator.Like)
            {
                if (Not) throw new Exception("模糊查询不支持Not");
                return $"{columnName}.Contains({parameterName})";
            }

            string ope = string.Empty;
            switch (Operator)
            {
                case Operator.Gt:
                    ope = Not ? "<=" : ">";
                    break;
                case Operator.Ge:
                    ope = Not ? "<" : ">=";
                    break;
                case Operator.Lt:
                    ope = Not ? ">=" : "<";
                    break;
                case Operator.Le:
                    ope = Not ? ">" : "<=";
                    break;
                default:
                    ope = Not ? "<>" : "=";
                    break;
            }

            return $"{columnName} {ope} {parameterName}";
        }
    }
}
